/**
 * 职工表
 * @TransactionAnnotation表示开启事务
 */
export default class StaffService {
    /**
     * 注册用户
     * @param table                 指定表名称
     * @param user                  用户属性
     * @returns {Promise<*>|void}
     *
     */
    addStaffEntity(entity) {
        return this['session'].save('t_staff', entity);
    }

    /**
     * 保存
     * @param table
     * @param userName
     * @returns {*}
     */
    removeStaffEntity(entity) {
        return this['session'].remove('t_staff', entity);
    }

    /**
     * 更新
     * @param table
     * @param entity
     * @returns {*}
     */
    updateStaffEntity(entity) {
        return this['session'].update('t_staff', entity);
    }

    /**
     * 查询
     * @param start
     * @param size
     * @param keyWord   关键字
     * @param field     字段
     * @param isRider   0 骑手 1管理人员
     * @returns {Promise<unknown>}
     */
    listEntities(start, size, keyWord, field) {
        return new Promise(async (resolve, reject) => {
            try {
                const sql = keyWord ? "WHERE " + field + " LIKE '%" + keyWord + "%'" : "" + "ORDER BY t_createAt DESC"
                const rows = await this['session'].query('t_staff', sql, [], start, size);
                const count = await this['session'].exeSQL("select count(*)  from t_staff " + sql, []);
                resolve({total: count[0]['count(*)'], records: rows});
            } catch (e) {
                reject(e)
            }
        })
    }



    /**
     * 查询管理人员
     * @param start
     * @param size
     * @param keyWord
     * @param field
     * @param isRider
     * @returns {Promise<unknown>}
     */
    listStaffEntities(start, size, keyWord, field){
        return this.listEntities(start, size, keyWord, field,)
    }


}


